<?php

namespace App\Serializers;
use League\Fractal\Serializer\ArraySerializer;

class DataArraySerializer extends ArraySerializer
{

    /**
     * Serialize a collection.
     *
     * @param string $resourceKey
     * @param array $data
     *
     * @return array
     */
    public function collection($resourceKey, array $data)
    {
        if (is_null($resourceKey)) {
            $resultData = ['status_code' => 200, 'message' => 'success', 'data' => $data];
            if (!empty($resourceKey)) {
                $resultData['total'] = $resourceKey;
            }
            return $resultData;
        }
        if (empty($resourceKey)) {
            return $data;
        }

        return [$resourceKey => $data];


    }

    /**
     * Serialize an item.
     *
     * @param string $resourceKey
     * @param array $data
     *
     * @return array
     */
    public function item($resourceKey, array $data)
    {
        if (is_null($resourceKey)) {
            return ['status_code' => 200, 'message' => 'success', 'data' => $data];
        }
        if (empty($resourceKey)) {
            return $data;
        }
        return [$resourceKey => $data];


    }

    /**
     * Serialize null resource.
     *
     * @return array
     */
    public function null()
    {
        return ['status_code' => 200, 'message' => 'success', 'data' => []];
    }
}